<template>
    <div>

      <el-dialog :visible.sync="visible" width="50%" center :before-close="handleClose" append-to-body title="文件夹列表"  >
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="grid-left" style="border-right: 10px solid #eee;height: 100%;">
                  <el-link type="primary" style="bottom: 5px;">文件夹一级分类</el-link>
                  <el-form ref="form" :model="form" label-width="80px">
                      <el-form-item label="">
                          <el-radio-group v-model="form.folder_id" @change="handleRadioChange1">

                              <el-radio v-for="(option, index) in tableData1" :key="index" v-model="option.id" :label="option.id" style="width: 100%;padding-top: 10px;">
                                  {{option.title}}
                              </el-radio>

                          </el-radio-group>
                      </el-form-item>
                  </el-form>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-right" style="border-right: 10px solid #eee;height: 100%;">
              <el-link type="primary" style="bottom: 5px;">文件夹二级分类</el-link>
              <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="">
                  <el-radio-group v-model="form.folder_id" @change="handleRadioChange2">

                    <el-radio v-for="(option, index) in tableData2" :key="index" v-model="option.id" :label="option.id" style="width: 100%;padding-top: 10px;">
                          {{option.title}}
                    </el-radio>

                  </el-radio-group>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="grid-right">
              <el-link type="primary" style="bottom: 5px;">文件夹三级分类</el-link>
              <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="">
                  <el-radio-group v-model="form.folder_id" @change="handleRadioChange3">

                    <el-radio v-for="(option, index) in tableData3" :key="index" v-model="option.id" :label="option.id" style="width: 100%;padding-top: 10px;">
                        {{option.title}}
                    </el-radio>

                  </el-radio-group>
                </el-form-item>
              </el-form>
            </div>
          </el-col>
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button @click="handleClose" size="small">取 消</el-button>
          <el-button type="primary"  @click="submitForm('form')"  size="small">确 定</el-button>
        </div>
      </el-dialog>

<!--        <el-dialog :visible.sync="visible" width="30%" center :before-close="handleClose" append-to-body :title="'文件夹列表'"  >-->
<!--            <el-row type="flex" justify="center">-->
<!--                <el-form ref="form" :model="form" label-width="80px">-->
<!--                    <el-form-item label="">-->
<!--                        <el-radio-group v-model="form.folder_id" >-->

<!--                            <el-radio v-for="(option, index) in tableData" :key="index" v-model="option.id" :label="option.id" style="width: 100%;padding-top: 10px;">-->
<!--                                {{option.title}}-->
<!--                            </el-radio>-->

<!--                        </el-radio-group>-->
<!--                    </el-form-item>-->
<!--                </el-form>-->
<!--            </el-row>-->
<!--            <div slot="footer" class="dialog-footer">-->
<!--                <el-button @click="handleClose" size="small">取 消</el-button>-->
<!--                <el-button type="primary"  @click="submitForm('form')"  size="small">确 定</el-button>-->
<!--            </div>-->
<!--        </el-dialog>-->

    </div>
    
</template>

<script>
import {editFolder, getFolderList, moveFiles,getFolderLevel} from "@/api/kanke/textbook/coursewarepub";

export default {
    name: "ShowFolderList",
    data() {
        return {
            loading: false,
            form:{
                folder_id:'',
                parent_id:0,
            },
            tableData1: [],  //文件夹一级分类
            tableData2:[],  //文件夹二级分类
            tableData3:[]  //文件夹三级分类
        }
    },
    props:{
        visible: {
            type: Boolean,
            default: false
        },
        mutiFileIds:{
            type:Array,
            default:[]
        }  
    },
    mounted() {
        this.init();
    },
    methods: {
        init() {
            this.loading = true;
            getFolderList(this.form).then(res => {
                console.log('now folder parent_id',this.form.parent_id);
                console.log('now folder folder_level',this.form.folder_level);
                console.log('getFolderList',res);
                if (res.code == 200) {
                  this.tableData1 = res.data.data
                }
                this.loading = false
            })
        },
        handleRadioChange1(value){
          console.log('handleRadioChange1单选按钮被点击，选中的值为：', value);
          this.form.id = value;
          this.form.folder_id = value;
          this.loading = true;
          this.form.parent_id = value;
          getFolderList(this.form).then(res => {
            if (res.code == 200) {
              this.tableData2 = res.data.data
            }
            this.loading = false
          })
        },
        handleRadioChange2(value){
          console.log('handleRadioChange2单选按钮被点击，选中的值为：', value);
          this.form.id = value;
          this.form.folder_id = value;
          this.loading = true;
          this.form.parent_id = value;
          getFolderList(this.form).then(res => {
            if (res.code == 200) {
              this.tableData3 = res.data.data
            }
            this.loading = false
          })
        },
        handleRadioChange3(value){
          console.log('handleRadioChange3单选按钮被点击，选中的值为：', value);
          this.form.id = value;
          this.form.folder_id = value;
        },
        //关闭抽屉
        handleClose(){
            this.$emit('update:visible', false);
        },
        submitForm(){
            console.log('mutiFileIds',this.mutiFileIds);
            console.log('form data',this.form.folder_id);
            let obj = Object.assign(this.form,{'mutiFileIds':this.mutiFileIds});
            moveFiles(obj).then((res) => {
                // console.log(res)
                if (res.code == 200) {
                    this.msgSuccess(res.msg);
                    //this.$emit('update:visible', false);
                    this.$emit('reloadInit');
                } else {
                    this.msgError(res.msg);
                }
            })
        }
    }
}
</script>

<style scoped>
::v-deep .el-dialog__header{
    background: #03A7EF;
}
</style>